<?php defined('API') or exit();?>
<div style="border:1px solid #ddd">
        <div style="background:#f5f5f5;padding:20px;position:relative">
            <h4>修改接口<span style="font-size:12px;padding-left:20px;color:#a94442">注:"此色"边框为必填项</span></h4>
            <div style="margin-left:20px;">
                <form action="?act=api&tag=<?php echo $_GET['tag']?>&type=do&op=edit" method="post">
                    <h5>基本信息</h5>
                    <div class="form-group has-error">
                        <div class="input-group">
                            <div class="input-group-addon">接口编号</div>
                            <input type="hidden" name="id" value="<?php echo $info['id']?>"/>
                            <input type="text" class="form-control" name="num" placeholder="接口编号" value="<?php echo $info['num']?>" required="required">
                        </div>
                    </div>
                    <div class="form-group has-error">
                        <div class="input-group">
                            <div class="input-group-addon">接口名称</div>
                            <input type="text" class="form-control" name="name" placeholder="接口名称" value="<?php echo $info['name']?>" required="required">
                        </div>
                    </div>
                    <div class="form-group has-error">
                        <div class="input-group">
                            <div class="input-group-addon">请求地址</div>
                            <input type="text" class="form-control" name="url" placeholder="请求地址" value="<?php echo $info['url']?>" required="required">
                        </div>
                    </div>
                    <div class="form-group">
                        <textarea name="des" class="form-control" placeholder="描述"><?php echo $info['des']?></textarea>
                    </div>
                    <div class="form-group" required="required">
                        <select class="form-control" name="type">
                            <?php
                                $selected[0] = ($info['type'] == 'GET') ? 'selected' : '';
                                $selected[1] = ($info['type'] == 'POST') ? 'selected' : '';
                            ?>
                            <option value="GET"  <?php echo $selected[0]?>>GET</option>
                            <option value="POST" <?php echo $selected[1]?>>POST</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <h5>请求参数</h5>
                        <table class="table">
                            <thead>
                            <tr>
                                <th class="col-md-2">参数名</th>
                                <th class="col-md-2">属性</th>
                                <th class="col-md-2">类型</th>
                                <th class="col-md-2">必传</th>
                                <th class="col-md-2">缺省值</th>
                                <th class="col-md-2">描述</th>
                                <th class="col-md-2">
                                    <button type="button" class="btn btn-success" onclick="add()">新增</button>
                                </th>
                            </tr>
                            </thead>
                            <tbody id="parameter">

                            <?php $count = count($info['parameter']['name']);?>
                            <?php for($i=0;$i<$count;$i++){ ?>
                            <tr>
                                <td class="form-group has-error">
                                    <input type="text" class="form-control" name="p[name][]" placeholder="参数名" value="<?php echo $info['parameter']['name'][$i]?>" required="required">
                                </td>
                                <td class="form-group has-error">
                                    <input type="text" class="form-control" name="p[prp][]" placeholder="属性" value="<?php echo $info['parameter']['prp'][$i]?>" required="required">
                                </td>
                                <td class="form-group has-error">
                                    <select class="form-control" name="p[type][]">
                                    	<option value="string"<?php if($info['parameter']['type'][$i]=='string'){?> selected="selected"<?php }?>>string</option>
                                        <option value="int"<?php if($info['parameter']['type'][$i]=='int'){?> selected="selected"<?php }?>>int</option>
                                        <option value="long"<?php if($info['parameter']['type'][$i]=='long'){?> selected="selected"<?php }?>>long</option>
                                        <option value="float"<?php if($info['parameter']['type'][$i]=='float'){?> selected="selected"<?php }?>>float</option>
                                        <option value="double"<?php if($info['parameter']['type'][$i]=='double'){?> selected="selected"<?php }?>>double</option>
                                        <option value="file"<?php if($info['parameter']['type'][$i]=='file'){?> selected="selected"<?php }?>>file</option>
                                    </select>
                                </td>
                                <td>
                                    <?php
                                        $selected[0] = ($info['parameter']['must'][$i] == 'Y') ? 'selected' : '';
                                        $selected[1] = ($info['parameter']['must'][$i] == 'N') ? 'selected' : '';
                                    ?>
                                    <select class="form-control" name="p[must][]">
                                        <option value="Y" <?php echo $selected[0]?>>Y</option>
                                        <option value="N" <?php echo $selected[1]?>>N</option>
                                    </select>
                                </td>
                                <td><input type="text" class="form-control" name="p[default][]" placeholder="缺省值" value="<?php echo $info['parameter']['default'][$i]?>"></td>
                                <td><textarea name="p[des][]" rows="1" class="form-control" placeholder="描述"><?php echo $info['parameter']['des'][$i]?></textarea></td>
                                <td><button type="button" class="btn btn-danger" onclick="del(this)">删除</button></td>
                            </tr>
                            <?php } ?>

                            </tbody>
                        </table>
                    </div>
                    
                    <hr style="border-bottom: 2px solid black;font-weight: bold;">
                    
                    <?php 
                    $result = $info['result'];
                    if (empty($result)){
                    ?>
                    
                    <?php }else{
                   foreach ($result as $key=>$val){ 
                   ?>
                   <div class="form-group" id="div_<?php echo $key ?>">
                   		<?php if($key=='default'){?>
                   		<h5>返回结果</h5>
                    	<input type="text" id="newTableName" placeholder="子表格名称" style="width: 100px">
                        <button type="button" class="btn btn-success" onclick="add_new_table()">新增表格</button>
                   		<?php }else{?>
                   		<h5 style='font-weight: bold;'><?php echo $key ?></h5>
                   		<?php }?>
                   		<table class='table' id='table_<?php echo $key ?>'>
                   		<thead>
                   		<tr>
							 <th class='col-md-2'>参数名</th>
							 <th class='col-md-2'>属性</th>
				             <th class='col-md-2'>类型</th>
				             <th class='col-md-2'>缺省值</th>
				             <th class='col-md-2'>描述</th>
				             <th class='col-md-2'>
				                 <button type='button' class='btn btn-success' onclick='add_result("<?php echo $key ?>")'>新增</button>
				                 <button type='button' class='btn btn-danger' onclick='$("#div_<?php echo $key ?>").remove()'>删除</button>
				             </th>
			             </tr>
						</thead>
						<tbody>
						<?php 
							for($i=0;$i<count($val['name']);$i++){
						?>							
						<tr>
							 <td class="form-group has-error">
                                  <input type="text" class="form-control" name="r[<?php echo $key ?>][name][]" placeholder="参数名" value="<?php echo $val['name'][$i]?>" required="required">
                              </td>
                              <td class="form-group has-error">
                                  <input type="text" class="form-control" name="r[<?php echo $key ?>][prp][]" placeholder="属性" value="<?php echo $val['prp'][$i]?>" required="required">
                              </td>
                              <td>
                               <select class="form-control" name="r[<?php echo $key ?>][type][]">
	                              <option value="string"<?php if($val['type'][$i]=='string'){?> selected="selected"<?php }?>>string</option>
	                              <option value="int"<?php if($val['type'][$i]=='int'){?> selected="selected"<?php }?>>int</option>
                                  <option value="long"<?php if($val['type'][$i]=='long'){?> selected="selected"<?php }?>>long</option>
                                  <option value="list"<?php if($val['type'][$i]=='list'){?> selected="selected"<?php }?>>list</option>
                                  <option value="array"<?php if($val['type'][$i]=='array'){?> selected="selected"<?php }?>>array</option>
                                  <option value="object"<?php if($val['type'][$i]=='object'){?> selected="selected"<?php }?>>object</option>
                                  <option value="float"<?php if($val['type'][$i]=='float'){?> selected="selected"<?php }?>>float</option>
                                  <option value="double"<?php if($val['type'][$i]=='double'){?> selected="selected"<?php }?>>double</option>
                                  <option value="other"<?php if($val['type'][$i]=='other'){?> selected="selected"<?php }?>>other</option>
                              </select>
                               </td>
                              <td><input type="text" class="form-control" name="r[<?php echo $key ?>][default][]" placeholder="缺省值" value="<?php echo $val['default'][$i]?>"></td>
                              <td><textarea name="r[<?php echo $key ?>][des][]" rows="1" class="form-control" placeholder="描述"><?php echo $val['des'][$i]?></textarea></td>
                              <td><button type="button" class="btn btn-danger" onclick="del(this)">删除</button></td>
						</tr>	
						<?php }?>
						
						</tbody>
                   		</table>
                   </div>
                    
                    <?php }}?>
                    
                    
                    <div class="form-group" id="lastResult">
                        <h5>返回结果</h5>
                        <textarea name="re" rows="3" class="form-control" placeholder="返回结果"><?php echo $info['re']?></textarea>
                    </div>
                    <div class="form-group">
                        <h5>备注</h5>
                        <textarea name="memo" rows="3" class="form-control" placeholder="备注"><?php echo $info['memo']?></textarea>
                    </div>
                    <div class="form-group">
                        <h5>状态</h5>
                        <select name="status" class="form-control">
                        	<option value="0"<?php echo $info['status']==0?'  selected="selected"':''?>>未完成</option>
                        	<option value="1"<?php echo $info['status']==1?'  selected="selected"':''?>>完成</option>
                        	<option value="2"<?php echo $info['status']==2?'  selected="selected"':''?>>作废</option>
                        </select>
                    </div>
                    <button class="btn btn-success">Submit</button>
                </form>
            </div>
        </div>
    </div>
   <script src="./MinPHP/res/api.js"></script>
